<?php
include("include/db.php");

$in_cat		= $_GET['cat'];
if($in_cat != ''){$cat_from = ", film_cat "; $cat_sql = "  AND films.film_id = film_cat.film_id AND film_cat.cat_id='$in_cat' ";}

//$in_country		= $_GET['country'];
//if($in_country != ''){$country_sql = " AND films.country='$in_country' ";}

$in_venue		= $_GET['venue'];
if($in_venue != ''){$venue_sql = " AND screenings.venue_id='$in_venue' ";}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sebastopol Documentary Film Festival</title>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>



<link type="text/css" href="main-events.css" rel="stylesheet" />

<style type="text/css">
	
	body{color: black;}
	
	a{color: black;}
</style>
</head>
<body class="sub">
<div id="container">
<div id="wrapper">
  <div id="left">
    <div class="logo">

    </div>
     	
     	<?php include "include/menu.php"; ?>
    
    <!-- end main nav -->
    <br class="clear" />
  </div>
  <!-- end left -->
  <div id="right">
    <div class="head">
    </div>
    <!-- end banner -->
    <div id="content">
      
      
      
      <form id="form1" name="form1" action="" method="get">    
                Categories:
                <select name="cat" id="cat" onchange="form1.submit();">
                    <option value="">all</option>
                    
                    <?php
                    
                    $result = mysql_query("SELECT * FROM categories  ORDER BY cat_name", $db);
                    	while ($myrow2 = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
                    	<option value="<?php echo $myrow2["cat_id"];?>" <?php if($myrow2["cat_id"] == $in_cat){echo "selected";}?>><?php echo $myrow2["cat_name"];?></option>

                    	<?php }?>

                  </select>
                  
                  <!--
                   Country:
                <select name="country" id="country" onchange="form1.submit();">
                    <option value="">all</option>
                    
                    <?php
                    
                    $result = mysql_query("SELECT DISTINCT(country) FROM films  ORDER BY country", $db);
                    	while ($myrow2 = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
                    	<option value="<?php echo $myrow2["country"];?>" <?php if($myrow2["country"] == $in_country){echo "selected";}?>><?php echo $myrow2["country"];?></option>

                    	<?php }?>

                  </select>
                  -->
                   Venue:
                <select name="venue" id="venue" onchange="form1.submit();">
                    <option value="">all</option>
                    
                    <?php
                    
                    $result = mysql_query("SELECT * FROM venues ORDER BY venue_name", $db);
                    	while ($myrow2 = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
                    	<option value="<?php echo $myrow2["venue_id"];?>" <?php if($myrow2["venue_id"] == $in_venue){echo "selected";}?>><?php echo $myrow2["venue_name"];?></option>

                    	<?php }?>

                  </select>
                <a href="film_list.php">Click Here to See Full List of Films (alphabetical)</a>
              </form>  <hr>
                
                
                 <table width="95%" border="0" class="underline">

              <tbody>
              <?php
              $film_array = array();$x = 0;
	$query = "SELECT screenings.event_title, screenings.screen_id, screenings.date, screenings.time, screenings.type, venues.venue_name, venues.venue_id, films.title, films.film_id, films.director, films.year_produced, films.runtime, films.ticket_link FROM screenings,venues,films  $cat_from WHERE screenings.venue_id = venues.venue_id AND screenings.film_id = films.film_id $cat_sql $country_sql $venue_sql ORDER BY screenings.date, screenings.time, screenings.screen_order desc";
	$result = mysql_query($query, $db);
	//echo $query;
      	while ($myrow = mysql_fetch_array($result, MYSQL_ASSOC)) { 
      	if($class == 'row2'){$class = 'row1';}else{$class = 'row2';}
      	if($current_day != $myrow['date']){
      	   		$current_day = $myrow['date'];
      	   		?>
      	   		<tr>
      	   			<td colspan="5" valign="top"><br><h2><?php echo date("l, F j", strtotime($current_day));?></h2></td>
      	   		</tr>
      	   		<?php
      	   	}
      	
      	if(!in_array($myrow['screen_id'], $film_array)){
      	
      		if($myrow['screen_id'] != 0){$film_array[$x] = $myrow['screen_id'];$x++;}
      		
      		
      		
      		if($myrow[type] == 'f'){
      		
      			$title = $myrow[title];
      			$edit_link = "<a href=\"film_edit.php?id=$myrow[film_id]\">$title</a>";
      		
      		
      		}
      		
      		
      		if($myrow[type] == 'e'){
      		
      			$title = $myrow[event_title];
      			$edit_link = "<a href=\"event_edit.php?id=$myrow[screen_id]\">$title</a>";
      		
      		
      		}

      		      	
      	?>
      	
      	<tr class="<?php echo $class;?>">
      		<td width="10px"></td>
      		<td valign="top"><?php echo date("g:i a", strtotime(substr($myrow[time], 3)));?></td>
      		<td width="45%"><strong><a href="film.php?screen=<?php echo $myrow[screen_id];?>"><?php echo $title;?></a></strong> <br>
      			<small><?php if($myrow[type] == 'f'){ echo $myrow['director']." ".$myrow['year_produced']." | ".$myrow['runtime']." min."; } ?></small>
      			
      			<?php	
      					$query2 = "SELECT screenings.event_title, screenings.screen_id, screenings.date, screenings.time, screenings.type, venues.venue_name, venues.venue_id, films.title, films.film_id, films.director, films.year_produced, films.runtime, films.ticket_link FROM screenings,venues,films, film_cat WHERE screenings.venue_id = venues.venue_id AND screenings.film_id = films.film_id AND films.film_id = film_cat.film_id AND screenings.date='$current_day' AND screenings.time='$myrow[time]' AND screenings.venue_id='$myrow[venue_id]' AND screenings.film_id != '$myrow[film_id]' GROUP BY screenings.film_id ORDER BY screenings.date, screenings.time";
						$result2 = mysql_query($query2, $db);
						//echo $query2;
						if(mysql_num_rows($result2) != 0){echo "<div style=\"margin-left:20px; padding-left: 5px; border-left: thin solid grey;\"><em><small>Screens with...</small></em>";}
					      	while ($myrow2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { 
					      	if(!in_array($myrow2['screen_id'], $film_array)){
					      	if($myrow2['screen_id'] != 0){$film_array[$x] = $myrow2['screen_id'];$x++;}
					      	?>
					      	<br>
					      	<small><strong><a href="film.php?screen=<?php echo $myrow2[screen_id];?>"><?php echo $myrow2[title];?></a></strong> <br>
      			<?php if($myrow2[type] == 'f'){ echo $myrow2['director']." ".$myrow2['year_produced']." | ".$myrow2['runtime']." min."; } ?></small>
					      		
					      <?php } } if(mysql_num_rows($result2) != 0){echo "</div>";} ?>		
      		
      		
      		</td>
      		<td><a href="venue.php?id=<?php echo $myrow['venue_id'];?>"><?php echo $myrow['venue_name'];?></a></td>
      		<td><?php if($myrow['ticket_link'] != ''){echo "<a href=\"$myrow[ticket_link]\" target='_blank'>$ticket_image</a>";}?></td>
      	</tr>
            		  
   <?php $nolist = ''; } } ?>              

                </tr>
              </tbody>
            </table>
<br><br><br>

      
      
      
      
      <br class="clear" /> 
    </div><!-- end content -->
    <div id="footer">
   <p> &copy;2009 Sebastopol Center for the Arts and Trinity Productions. All rights reserved.</p>
    </div>
  </div><!-- end right -->
  </div><!-- end wrapper -->
  <br class="clear" />
</div><!-- end container -->
</body>
</html>
